
CC	= gcc
LD	= $(CC)

CFLAGS   = -Wall -Wunused-but-set-variable

target = GR_BLE_OTA_M

objdir = ./build
srcdir = .

subdir = . \

incdir =  -I ../include/ -L ../lib/libwebsockets.a 

#inclib = -lbluetooth -lpthread  -lwebsockets
inclib = -lbluetooth -lpthread -lwebsockets
allsrc = $(foreach dir, $(subdir), $(wildcard $(srcdir)/$(dir)/*.c))

allobj = $(patsubst $(srcdir)/%.c, $(objdir)/%.o, $(allsrc))

	
$(objdir)/%.o: $(srcdir)/%.c
	@echo Compiling $<...
	$(CC) $(CFLAGS) -c $< -o $@
	
ifeq ($(MAKELEVEL), 2)
include $(alldep)
endif
	
.PHONY:	init clean

init: 
	@mkdir -p $(dir $(allobj))
	@$(MAKE) -s depend
	
depend: $(alldep)
	@$(MAKE) -s target

target: $(alldep) $(allobj)
	@echo Linking target...
	@$(LD) $(LDFLAGS) -fpic -o  $(objdir)/$(target) $(allobj) $(inclib)
	cp $(objdir)/$(target) ./
	@echo Link done!
	
clean:
	@rm -rf $(target) $(objdir)
	@echo clean done.
